//
//  HWChangeThePasswordViewController.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/3/10.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWChangeThePasswordViewController.h"

@interface HWChangeThePasswordViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIView *beijingView;
@property (weak, nonatomic) IBOutlet UITextField *oldTextField;
@property (weak, nonatomic) IBOutlet UITextField *xingmimTextField;
@property (weak, nonatomic) IBOutlet UITextField *querenTextFeild;
@property (weak, nonatomic) IBOutlet UILabel *miaoshuwenziLabel;
@property (weak, nonatomic) IBOutlet UIButton *tijiaoBut;

@end

@implementation HWChangeThePasswordViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置UI
    [self setupUI];
   
}


// 设置UI
- (void)setupUI {
    
    self.navigationItem.title = @"修改密码";
    self.view.backgroundColor = beijingyanSe;
    self.beijingView.layer.cornerRadius = 8;
    self.beijingView.layer.masksToBounds = YES;
    self.tijiaoBut.layer.cornerRadius =  2;
    self.tijiaoBut.layer.masksToBounds = YES;
    
   // self.oldTextField.

    self.oldTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 44)];
    self.oldTextField.leftViewMode = UITextFieldViewModeAlways;
    self.oldTextField.layer.cornerRadius =  2;
    self.oldTextField.layer.masksToBounds = YES;
    self.oldTextField.delegate = self;
    self.oldTextField.keyboardType = UIKeyboardTypeASCIICapable;
      self.oldTextField.secureTextEntry = YES;
    
    
    self.xingmimTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 44)];
    self.xingmimTextField.leftViewMode = UITextFieldViewModeAlways;
    self.xingmimTextField.layer.cornerRadius =  2;
    self.xingmimTextField.layer.masksToBounds = YES;
    self.xingmimTextField.delegate = self;
     self.xingmimTextField.keyboardType = UIKeyboardTypeASCIICapable;
      self.xingmimTextField.secureTextEntry = YES;
    
    self.querenTextFeild.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 44)];
    self.querenTextFeild.leftViewMode = UITextFieldViewModeAlways;
    self.querenTextFeild.layer.cornerRadius =  2;
    self.querenTextFeild.layer.masksToBounds = YES;
    self.querenTextFeild.delegate = self;
    self.querenTextFeild.keyboardType = UIKeyboardTypeASCIICapable;
    self.querenTextFeild.secureTextEntry = YES;
     
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView)];
    
    [self.view addGestureRecognizer:tap];
    
    
    
    
    
}



- (void)tapView {
    
    [self.view endEditing:YES];
    
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    [textField resignFirstResponder];
    
    return  YES;
    
}




//确认分享
- (IBAction)tijiaoBut:(UIButton *)sender {
    
    
    if (!(self.oldTextField.text.length > 0)) {
    
        [MBProgressHUD showError:@"请输入旧密码"];
        
        return;
        
        
        
    }else if ([WMUtil isBlank:self.oldTextField.text]) {
        
        [MBProgressHUD showError:@"旧密码不能有空格"];
        return;
        
    }
    else if (!(self.xingmimTextField.text.length > 0)) {
        
           [MBProgressHUD showError:@"请输入新密码"];
             
            return;
        
        
        
    }else if ([WMUtil isBlank:self.oldTextField.text]) {
        
        [MBProgressHUD showError:@"旧密码不能有空格"];
        return;
        
    } else if ([WMUtil isBlank:self.xingmimTextField.text]) {
        
        
         [MBProgressHUD showError:@"新密码不能有空格"];
    
         return;
              
        
        
    }else if (![self.xingmimTextField.text isEqualToString:self.querenTextFeild.text]){
        
             [MBProgressHUD showError:@"新密码和确认密码不一致"];
                   
            return;
        
        
        
    } else if (!(self.xingmimTextField.text.length > 7)) {
        
         [MBProgressHUD showError:@"密码必须大于8位有效数字或者字母"];
           return;
        
        
    }
        
    
    
    
             NSLog(@"基本验证成功");
    
    
    
   
             NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
             NSString *uid =  [HWLocallyStoredData getLoginUserID];
             NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tStr,@"adesxloksy13s98adv"];
             NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
             NSString *passwd = self.xingmimTextField.text;
             NSString *oldpasswd =  self.oldTextField.text;
    
    
            
            
            
              NSDictionary *parametes = @{      @"ios" : @"1",
                                           @"ct" : @"app",
                                            @"ac" : @"my_edit",
                                            @"t" : tStr,
                                            @"uid":uid,
                                            @"passwd" :passwd,
                                            @"oldpasswd" :oldpasswd,
                                            @"sign" :signStrMd5
                                           
                                            };
            
            
                [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                      
                     

                      NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                      if ([codeStr intValue] == 1) {
                     
                          
                          
                             [MBProgressHUD showError:response[@"message"]];
                            NSLog(@"%@",response);
                           [self.navigationController popViewControllerAnimated:YES];
                          
                          
 
                     
                          
                    
                    

                           
                      } else {
                          
                        [MBProgressHUD showError:response[@"message"]];
                                        
                    
                          
                      }
                      
                 
                      
                  } failure:^(NSString *error) {
                     // [SVProgressHUD dismiss];
                      
                      [MBProgressHUD showSuccess:@"登录失败"];
                      [MBProgressHUD hideHUD];
                      
                      
                      
                      
                  }];
            
    
    
    
    
}




@end
